<template>
    <div class="tax-info" v-loading="loading">
        <DescribeSpecCom class="mb20 mt20 " :list="formList" :form="form" />
        <el-collapse v-model="activeNames" accordion @change="handleChange">
            <el-collapse-item v-for="(v, k) in tableObj" :key="v.prop" :name="k">
                <template #title>
                    <div> {{ v.label }}
                        <span class="ml5" style="color:red">
                            {{ form[v.prop1]?.num || 0 }}
                        </span>
                        <span style="color:#283de6;margin-left: 2px;">{{ v.unit || '条' }}</span>
                    </div>
                </template>
                <tableCom v-if="v.type == 'tableCom'" :columns="v.children" :dataList="getDataList(v)" :key="activeTab" />
                <tableCom2 v-if="v.type == 'tableCom2'" :dataList="form[v.prop1][v.prop2]" timeType="payTaxTime"
                    totalType="taxAmount" dataType="taxType" />
            </el-collapse-item>
            <el-collapse-item title="近三年纳税情况明细表（元）" name="5">
                <div class="taxInfo-list">
                    <div class="taxInfo-item">
                        <el-table :data="threeYearDatas">
                            <el-table-column label="月份" align="center" prop="month">
                                <template #default="{ row }">
                                    <div>
                                        {{ row.month + '月份' }}
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column v-for="(it, i) in tableHeader" :key="i" :label="it.year" align="center">
                                <template #default="{ row }">
                                    <div>
                                        {{ row[it.year] || 0 }}
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="total-info-list">
                            <div class="total-info-item">年度汇总</div>
                            <div class="total-info-item" v-for="(v, i) in form.las3YTaxPaidInfos" :key="i">{{ v.sumMoney }}
                            </div>
                        </div>
                    </div>
                </div>
            </el-collapse-item>
        </el-collapse>
    </div>
</template>

<script setup>
import { taxTypeEnum, payTaxTimeEnum } from '@/utils/enum';
import { getTaxInfo } from '@/api/taxReportManage';
import tableCom from '../components/tableCom';
import tableCom2 from '../components/tableCom2';
import DescribeSpecCom from '../components/describeSpecCom';

const route = useRoute()
const form = ref({
    payTaxWarnViewModels: {}
})
const loading = ref(false)
const tableHeader = ref([])
const threeYearDatas = ref([]);
const activeNames = ref(null)
const formList = ref([{
    label: '纳税信用等级',
    prop: 'creditLevelPrevyr',
},
{
    label: '纳税类型',
    prop: 'nsLx',
},
{
    label: '类型生效日期',
    prop: 'type_effective_date',
},
{
    label: '税务登记日期',
    prop: 'tax_registration_date',
},
{
    label: '当前是否欠税',
    prop: 'isOweTax',
},
{
    label: '欠税金额',
    prop: 'oweTaxAmount',
    unit: '元',
},
{
    label: '近3年最早纳税月',
    prop: 'las3yTaxEarMonth',
},
{
    label: '近2年最早纳税月',
    prop: 'las2yTaxEarMonth',
},
{
    label: '近12月实缴税额',
    prop: 'taxPper12MonthPaid',
    unit: '元',
},
{
    label: '近12月申报销额',
    prop: 'taxPpev12MthsSale',
    unit: '元',
},
{
    label: '近24月实缴税额',
    prop: 'taxPper24MonthPaid',
    unit: '元',
},
{
    label: '近24月申报销额',
    prop: 'taxPpev24MthsSale',
    unit: '元',
},
],)
const tableObj = ref({
    0: {
        label: '纳税数据同环警标',
        prop1: 'payTaxWarnViewModels',
        prop2: 'payTaxWarnList',
        type: 'tableCom2',
        unit: '项',
    },
    1: {
        label: '银行税贷预警指标',
        prop1: 'bankTaxWarnViewModels',
        prop2: 'bankTaxWarnList',
        type: 'tableCom',
        unit: '项',
        children: [
            { label: '月份', prop: 'month' },
            { label: '零申月数', prop: 'zeroMonths', isRedFun: val => val >= 3 },
            { label: '零申连月', prop: 'zeroDecMonths', isRedFun: val => val >= 3 },
            { label: '滞纳次数', prop: 'lateMonths', isRedFun: val => val >= 3 },
            { label: '最高滞纳税额', prop: 'mostLateMonths', isRedFun: val => val >= 3 },
            { label: '断缴月数', prop: 'cutPayMonths', isRedFun: val => val >= 3 },
            { label: '断缴连月', prop: 'cutDecPayMonths', isRedFun: val => val >= 3 },
        ]
    },
    2: {
        label: '税务滞纳金明细',
        prop1: 'taxLateFeeViewModels',
        prop2: 'taxLateFeeList',
        type: 'tableCom',
        children: [
            { label: '开始时间', prop: 'beginDate' },
            { label: '滞纳金', prop: 'money' },
            { label: '项目名称', prop: 'projectName' },
            { label: '结束时间', prop: 'endTime' },
        ]
    },
    3: {
        label: '税务申报信息',
        prop1: 'taxApplyInfoViewModels',
        prop2: 'taxApplyInfoList',
        type: 'tableCom',
        children: [
            { label: '报表种类', prop: 'reportType' },
            { label: '所属期起', prop: 'beginTime' },
            { label: '所属期止', prop: 'endTime' },
            { label: '录入日期', prop: 'enterTime' },
        ]
    },
    4: {
        label: '税务违法记录信息',
        prop1: 'taxLllegalRecordInfoViewModels',
        prop2: 'taxLllegalRecordInfoList',
        type: 'tableCom',
        children: [
            { label: '违法行为名称', prop: 'name' },
            { label: 'LllegalMeans', prop: 'lllegalMeans' },
            { label: '违法事实', prop: 'lllegalFact' },
            { label: '处理状态', prop: 'processStatus', width: 120 },
            { label: '是否社保违法', prop: 'isSocial', width: 120 },
            { label: '违法所属期起', prop: 'beginTime', width: 120 },
            { label: '违法所属期止', prop: 'endTime', width: 120 },
        ]
    },
})

getInfo()
function getInfo() {
    const reqForm = { id: route.query.id }
    loading.value = true
    getTaxInfo(reqForm).then(res => {
        form.value = res.data

        tableHeader.value = res.data.las3YTaxPaidInfos.map(item => ({ year: item.year }));
        let hasMonth = {};
        let arrs = [];
        res.data.las3YTaxPaidInfos.forEach(item => {
            let obj = {};
            item.monthDetail.forEach((it, index) => {
                it.taxPaidDetails.forEach(ii => {
                    if (!hasMonth[it.month]) {
                        obj = { month: ii.month, [item.year]: ii.moneyCount }
                    } else {
                        obj = { moneyCount: ii.moneyCount };
                    }

                })
                if (!hasMonth[it.month]) {
                    arrs.push(obj);
                    hasMonth[it.month] = true;
                } else {
                    arrs[index][item.year] = obj.moneyCount;
                }

            })
        })

        threeYearDatas.value = [...arrs];
    }).finally(() => loading.value = false)
}

function getDataList(row) {
    if (form.value[row.prop1]) {
        return form.value[row.prop1][row.prop2]
    }
    return []
}
</script>
<style lang="scss" scoped>
:deep .el-collapse-item__content {
    padding-bottom: 0;
}

.total-info-list {
    display: flex;

    .total-info-item {
        width: 25%;
        padding: 10px 0;
        color: #fff;
        text-align: center;
        background-color: #409eff;
    }
}

.table-title {
    font-size: 18px;
    font-weight: bold;
    line-height: 44px;
    text-align: center;
    background-color: #f1f1f1;
}
</style>